package com.maxd.service.article;

import com.maxd.model.ArticleClassify;
import com.maxd.respository.article.ArticleClassifyJpaRepository;
import com.maxd.respository.article.ArticleClassifyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 分类
 */
@Service
public class ArticleClassifyServiceImpl implements ArticleClassifyService {

    @Autowired
    private ArticleClassifyRepository articleClassifyRepository;
    @Autowired
    private ArticleClassifyJpaRepository articleClassifyJpaRepository;

    @Override
    public ArticleClassify save(ArticleClassify articleClassify) {
        return articleClassifyJpaRepository.save(articleClassify);
    }

    @Override
    public List<ArticleClassify> selectArticleClassifyList() {
        return articleClassifyRepository.selectArticleClassifyList();
    }

    @Override
    public int updateStateByArticleClassifyId(Long articleClassifyId, Integer state) {
        return articleClassifyRepository.updateStateByArticleClassifyId(articleClassifyId,state);
    }

    @Override
    @Transactional
    public void updateStateByArticleClassifyIds(String articleClassifyIds) {
        for(String str:articleClassifyIds.split(",")){
            articleClassifyRepository.updateStateByArticleClassifyId(Long.parseLong(str),2);
        }
    }

    @Override
    public int updateClassifyNameByArticleClassifyId(Long articleClassifyId, String articleClassifyName) {
        return articleClassifyRepository.updateClassifyNameByArticleClassifyId(articleClassifyId,articleClassifyName);
    }

    @Override
    public int updateSortByArticleClassifyId(Long articleClassifyId, Integer sort) {
        return articleClassifyRepository.updateSortByArticleClassifyId(articleClassifyId,sort);
    }
}
